var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    properties = require('../conf/properties'),
    baseDao = require('./baseDao');

var placeSchema = new Schema(
	{
	    id : { type: Number, unique: true, required: true },
	    name : { type: String, required: true },
	    description : String,
	    links : [String], //URLs
	    images : [String], //URLs
	    categories : [Number], //Ids de Categorías
	    state : {
	    	type: String,
	    	enum: ['generated', 'published', 'unpublished', 'void'],
	    	default: 'generated',
	    	requided: true
	    },
	    geoId: Number, //Debe ser un id de un dato geográfico existente
	    location: {
		    country : { type: Number },
		    state : { type: Number },
		    city : { type: Number }
		},
	    extendedString : { type: String, unique: true}, //Autogenerado, nombre del place + location
	    created: {
	    	creationDate: { type: Date, default: Date.now },
	    	createdBy: Number
	    },
	    modified: {
	    	modifiedDate: { type: Date, default: Date.now },
	    	modifiedBy: Number
	    }
	}
);

//Conecto con la DB y seteo el Model
mongoose.connect(properties.mongodbConnectionURI);
var places = mongoose.model('places', placeSchema);

module.exports.getAll = function (short, callback) {
	baseDao.getAll(places, short, '["id", "name"]', callback);
}

module.exports.find = function (filters, callback) {
	baseDao.find(places, filters, false, callback);
}

module.exports.findOne = function (filters, callback) {
	baseDao.find(places, filters, true, callback);
}

module.exports.set = function (place, callback) {
	baseDao.set(places, place, callback);
}

module.exports.update = function (id, data, callback) {
	baseDao.update(places, 'id', id, data, callback);
}

module.exports.upsert = function (id, data, callback) {
	baseDao.upsert(places, 'id', id, data, callback);
}

module.exports.remove = function (id, callback) {
	baseDao.remove(places, 'id', id, callback);
}